class Solution
{
public:
    vector<int> minOperations(string boxes)
    {
        int n = boxes.size();
        vector<int> leftCount(n);
        vector<int> rightCount(n);
        leftCount[0] = boxes[0] == '1';
        rightCount[n - 1] = boxes[n - 1] == '1';
        vector<int> result;
        int cost = 0;
        for (int i = 1; i < n; ++i)
        {
            if (boxes[i] == '1')
            {
                leftCount[i] = leftCount[i - 1] + 1;
                cost += i;
            }
            else
            {
                leftCount[i] = leftCount[i - 1];
            }
        }
        for (int i = n - 2; i >= 0; --i)
        {
            if (boxes[i] == '1')
            {
                rightCount[i] = rightCount[i + 1] + 1;
            }
            else
            {
                rightCount[i] = rightCount[i + 1];
            }
        }
        result.push_back(cost);
        for (int i = 1; i < n; ++i)
        {
            cost += leftCount[i - 1];
            cost -= rightCount[i];
            result.push_back(cost);
        }
        return result;
    }
};